<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;
use think\facade\Db;
class GmEmailjob extends Model
{
    use SoftDelete;
     protected $deleteTime = "delete_time";
    // 获取列表
    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        
               //按任务名称查找
               if ($jobname = input("jobname")) {
                   $where[] = ["jobname", "like", "%" . $jobname . "%"];
               }
               //按发送类型(1.单人 2.单区 3.多区)查找
               if ($sendtype = input("sendtype")) {
                   $where[] = ["sendtype", "like", "%" . $sendtype . "%"];
               }
               //按发送人查找
               if ($sendu = input("sendu")) {
                   $where[] = ["sendu", "like", "%" . $sendu . "%"];
               }
               //按接收人查找
               if ($tou = input("tou")) {
                   $where[] = ["tou", "like", "%" . $tou . "%"];
               }
               //按物品列表查找
               if ($goods = input("goods")) {
                   $where[] = ["goods", "like", "%" . $goods . "%"];
               }
               //按发送时间查找
               $start = input("get.sendtime-start");
               $end = input("get.sendtime-end");
               if ($start && $end) {
                   $where[]=["sendtime","between",[$start,date("Y-m-d",strtotime("$end +1 day"))]];
               }
        $list = self::order('id','desc')->where($where)->paginate($limit);
        return ['code'=>0,'data'=>$list->items(),'extend'=>['count' => $list->total(), 'limit' => $limit]];
    }


    //获取定时发送内容
    public static function getSetingContent($id){
        return Db::query("select * from gmpre.gm_emailjob where id=:id", ['id' => $id]);
    }

}
